import Home from '@/views/Home'
import MyOrder from '@/views/MyOrder'
import OrderDetail from '@/views/MyOrder/OrderDetail'
import AddCartSuccess from "@/views/AddCartSuccess"



export default [
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/Search'),
  },
  {
    path: '/detail/:skuId',
    component: () => import('@/views/Detail'),
  },
  {
    path: '/addcartsuccess',
    component: AddCartSuccess
  },
  {
    path: '/home',
    component: Home
  },
  {
    path: '/myorder',
    component: MyOrder,
    children: [
      {
        path: 'orderdetail',
        component: OrderDetail,
      },
      {
        path: "",
        redirect: '/myorder/orderdetail'
      }
    ]
  },
  {
    path: '/trade',
    name:'Trade',
    component: ()=>import('@/views/Trade')
      
    }
  ,
  {
    path: '/paysuccess',
    name:'paysuccess',
    component: ()=>import('@/views/paySuccess')

  },
  {
    path: '/payment/:orderId?',
    name:'payment',
    component: ()=>import('@/views/payment'),

    
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      // 如果是从/trade而来 放行
      if (from.path.indexOf('/trade') !== -1) {
        next()
      } else { //不是从/trade而来 不放行
        next(false)
      }
    },
  },
  {
    path: '/register',
    component: () => import('@/views/register')
  },
  {
    path: '/login',
    component: () => import('@/views/login')
  },
  {
    path: '/',
    redirect: '/home'
  }
]
